package cc.comac.mom.webservice.impl;

import cc.comac.mom.datahandlers.entity.QualityPclrTestInvoiceDataHandler;
import cc.comac.mom.entity.QualityTestContentEntity;
import cc.comac.mom.util.ResultBean;
import cc.comac.mom.webservice.TestDataManageWebService;
import cc.comac.mom.webservice.TestPclrDataManageWebService;
import com.alibaba.ans.shaded.com.alibaba.fastjson.JSONObject;
import io.netty.util.internal.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.jws.WebService;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
@WebService(serviceName = "TestPclrDataManage", targetNamespace = "http://webservice.mom.comac.cc/", endpointInterface = "cc.comac.mom.webservice.TestPclrDataManageWebService")
public class TestPclrDataManageWebServiceImpl implements TestPclrDataManageWebService {

	@Autowired
	private QualityPclrTestInvoiceDataHandler qualityPclrTestInvoiceDataHandler;
	@Override
	public String reciveTestPclrResultInfo(String json) {
		QualityTestContentEntity qualityTestContentEntity= JSONObject.parseObject(json,QualityTestContentEntity.class);
		Map<String,String> resultMap = new HashMap<String,String>();
		resultMap.put("result", "true");
		resultMap.put("message", "");
		if (StringUtil.isNullOrEmpty(qualityTestContentEntity.getTestNo())) {
			resultMap.put("result", "false");
			resultMap.put("message", "实验编号不能为空！");
			return resultMap.toString();
		}
		if (StringUtil.isNullOrEmpty(qualityTestContentEntity.getTestUser())) {
			resultMap.put("result", "false");
			resultMap.put("message", "批准人姓名不能为空！");
			return resultMap.toString();
		}
		if (StringUtil.isNullOrEmpty(qualityTestContentEntity.getTestUserJobNumber())) {
			resultMap.put("result", "false");
			resultMap.put("message", "批准人工号不能为空！");
			return resultMap.toString();
		}
		if (qualityTestContentEntity.getApprovedDate()==null) {
			resultMap.put("result", "false");
			resultMap.put("message", "批准时间不能为空！");
			return resultMap.toString();
		}
		if (qualityTestContentEntity.getIsConform()==null) {
			resultMap.put("result", "false");
			resultMap.put("message", "符合规范要求不能为空！");
			return resultMap.toString();
		}
		if (StringUtil.isNullOrEmpty(qualityTestContentEntity.getFileUrl())) {
			resultMap.put("result", "false");
			resultMap.put("message", "实验文件不能为空！");
			return resultMap.toString();
		}
		if (StringUtil.isNullOrEmpty(qualityTestContentEntity.getFileName())) {
			resultMap.put("result", "false");
			resultMap.put("message", "实验文件名称不能为空！");
			return resultMap.toString();
		}
		qualityTestContentEntity.setTestName(qualityTestContentEntity.getFileName());
		// 更新实验内容数据和实验结果
		ResultBean resultBean =qualityPclrTestInvoiceDataHandler.updateByTestPclrDateManage(qualityTestContentEntity);
		if(!resultBean.success){
			resultMap.put("result", "false");
			resultMap.put("message", resultBean.getMessage());
		}
		return resultMap.toString();
	}
}
